import React from "react";
import StatusChild from "./StatusChild";

export default class StatusParent extends React.Component {
    state = {
        msg : "父组件状态",
        num : 10,
        sonData: ''
    }
    getData = (data) => {
        console.log(data);
        this.setState({sonData: data})
    }
    changeNum=()=>{
        this.setState({num: this.state.num + 1})
    }
    render(){
        return (
            <div>
                <h1>父组件</h1>
                <p>父组件信息: {this.state.msg}</p>
                <p>父组件num : {this.state.num}</p>
                <hr />
                {/* 父组件数据传递到子组件, 第二步参见 StatusChild.jsx */}
                <StatusChild toSonMsg = {this.state.msg} 
                num = {this.state.num}
                getSonData={this.getData}
                changeParentNum={this.changeNum}/>
                <p>子组件过来的数据: {this.state.sonData}</p>
                <p>子组件修改了num:{this.state.num}</p>
            </div>
        )
    }
}